<?php
 
namespace app\admin\service;

use app\admin\model\StudentClbum;
use think\Model;

class Student extends Model
{
    //根据学员id获取班级信息
    public function getStudentClbums($id) 
    {
        $model = new StudentClbum();
        $where['student_id'] = $id;
        $field = ['elite_clbum.id'=>'id','name','elite_clbum.course_id'=>'course_id','state','day_week','start_time','end_time'];
        $data = $model
        ->field($field)
        ->join('elite_clbum','elite_student_clbum.clbum_id = elite_clbum.id','LEFT')
        ->where($where)
        ->paginate(10);
        return $data;
    }
    
    //根据班级id学员信息
    public function getClbumStudents($id, $name =null )
    {
        $model = new StudentClbum();
        $where['clbum_id'] = $id;
        if (!is_null($name)) {
            if(is_numeric($name)){
                $where['elite_student.id|name']=   array('like','%'.$name.'%');
            }else{
                $where['name']    =   array('like', '%'.(string)$name.'%');
            }
        }
        $field = ['elite_student.id'=>'id','name','gender','state','phone','level','clbum_id'];
        $data = $model
        ->field($field)
        ->join('elite_student','elite_student_clbum.student_id = elite_student.id','LEFT')
        ->where($where)
        ->paginate(10);
        return $data;
    }
    
    public function quitClbum($clbum_id, $student_id) 
    {
        $map['clbum_id'] = $clbum_id;
        $map['student_id'] = $student_id;
        return StudentClbum::destroy($map);
    }

}